include ../config.mk
MAKE     = make
RPATH    = -Wl,-rpath,.
XCCFG    = $(shell which xcurses-config || echo bin/xcurses-config)
XCFLAGS  = "`$(XCCFG) --cflags` -Wall -DHAVE_XCURSES -fPIC"
XLDFLAGS = "`$(XCCFG) --libs` $(RPATH)"
CFLAGS   = -Wall -DHAVE_CURSES -fPIC
LDFLAGS  = -lcurses
UNAME    = `uname`
LIB      = libncwrap.so
ALL      = wrap.o $(LIB)
PIGGY    = $(LIB:.so=.dylib) wrap.dll

all:
	@case "x$(UNAME)" in       \
	  xDarwin)  $(MAKE) -f wrap-darwin.mk ;; \
	  x*)       $(MAKE) -f wrap.mk build  ;; \
	esac

build: $(ALL)

clean:
	-rm *~
distclean: clean
	-rm $(ALL) $(PIGGY)

libncwrap.so: wrap.o
	$(CC) -shared $(LDFLAGS) wrap.o -o libncwrap.so
	-strip -R .comment libncwrap.so
	strip libncwrap.so

ncwrap.dll: wrap.o
	$(CC) -shared wrap.o win32/pdcurses.a $(LDFLAGS) -o ncwrap.dll

xcurses:
	$(MAKE) CFLAGS=$(XCFLAGS) LDFLAGS=$(XLDFLAGS)

win: distclean
	$(MAKE) -f wrap.mk CC=$(MINGWGCC) \
              LDFLAGS="" \
              CFLAGS="-DWINFIX -DBUILD_DLL -DHAVE_CURSES -Iwin32" \
              ncwrap.dll
	-$(MINGWSTRIP) -R .comment ncwrap.dll
	$(MINGWSTRIP) ncwrap.dll
	chmod -x ncwrap.dll

wrap.c: wrap.h
wrap.o: wrap.c wrap.h
